//https://leetcode.cn/problems/symmetric-tree/submissions/555620837/
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return isSymmetricChild(root.left,root.right);
    }
    private boolean isSymmetricChild(TreeNode rootL,TreeNode rootR) {
        if (rootL == null && rootR == null) {
            return true;
        }
        if (rootL != null && rootR == null ||
                rootL == null && rootR != null ||
                rootL.val != rootR.val) {
            return false;
        }

        return isSymmetricChild(rootL.right,rootR.left) && isSymmetricChild(rootL.left,rootR.right);
    }
}